package top.lcm889.oj.leetcodeTop200;

/**
 * @author Coder-lcm
 * @date 2021/4/6
 *
 *      快慢双指针来解决
 */
public class LC80_删除数组中的重复项{
    public int removeDuplicates(int[] nums) {
        int len = nums.length;
        if (len <= 2) {
            return len;
        }
        int slow = 2, fast = 2;
        while (fast < len) {
            if (nums[slow - 2] != nums[fast]) {
                nums[slow] = nums[fast];
                ++slow;
            }
            ++fast;
        }
        return slow;
    }

    public static void main(String[] args) {
        LC80_删除数组中的重复项 test = new LC80_删除数组中的重复项();
        int[] nums = {1,1,2, 2, 2, 3};
        int res = test.removeDuplicates(nums);
        System.out.println(res);
        for (int i = 0; i < res; i++) {
            System.out.print(nums[i] + ",");
        }
    }
}
